package com.lzy.controller;

import java.util.Arrays;
import java.util.List;

import com.lzy.common.R;
import com.lzy.common.base.BaseController;
import com.lzy.context.LocalUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lzy.entity.SysMenuEntity;
import com.lzy.service.ISysMenuService;

/**
 * 菜单权限表
 *
 * @author lyw
 * @email lyw@gmail.com
 * @date 2023-02-02 17:06:20
 */
@Api(tags = "系统菜单")
@RestController
@RequestMapping("/sysmenu")
public class SysMenuController extends BaseController {
    @Autowired
    private ISysMenuService iSysMenuService;

    /**
     * 列表
     */
    @ApiOperation(value = "列表展示")
    @PostMapping("/list")
    public R list(){

        List<SysMenuEntity> list = iSysMenuService.selectPageList(LocalUser.getLoginUser().getId());
        return R.ok().put("page", list);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{menuId}")
    @ApiOperation(value = "菜单信息")
    public R info(@PathVariable("menuId") Long menuId){
		    SysMenuEntity sysMenu = iSysMenuService.getById(menuId);
        return R.ok().put("sysMenu", sysMenu);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存菜单")
    public R save(@RequestBody SysMenuEntity sysMenu){
		    iSysMenuService.save(sysMenu);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "更新菜单")
    public R update(@RequestBody SysMenuEntity sysMenu){
		    iSysMenuService.updateById(sysMenu);
        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除菜单")
    public R delete(@RequestBody Long[] menuIds){
		    iSysMenuService.removeByIds(Arrays.asList(menuIds));
        return R.ok();
    }

}
